package com.magic.web.common.controller;

import lombok.Data;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @description
 * @author wm
 * @date 2021/3/18
 */
@Data
public class StreamController {

    private static SimpleDateFormat YMD = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat MD = new SimpleDateFormat("yyyy-M-d");

    @Test
    public void test01() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List<Object> collect = list.stream().filter(c -> list.isEmpty()).collect(Collectors.toList());
        System.out.println(collect);
    }

    @Test
    public void test02() {
        Integer a = 1 + 2;
        Integer b = a * 3;
        Integer c = b - 4;
        System.out.println("c:" + c);

    }

    @Test
    public void test03() {
        /*BigDecimal bigDecimal = null;
        bigDecimal = BigDecimal.valueOf(0.0);
        System.out.println(bigDecimal);*/
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        Date date = new Date();
        calendar.setTime(date);
        //上周周日
        calendar.add(Calendar.DATE, -1);
        String lastWeekEnd = sdf.format(calendar.getTime());
        //上周周一
        calendar.add(Calendar.DATE, -6);
        String lastWeekStart = sdf.format(calendar.getTime());
        System.out.println(lastWeekStart);
        System.out.println(lastWeekEnd);
    }

    @Test
    public void test04() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M");
        Date date = new Date();
        String format = sdf.format(date);
        System.out.println(format);


        String time = "2021-03-12";
        Calendar instance = Calendar.getInstance();
        instance.setTime(DateUtils.parse(time, "yyyy-M"));
        instance.add(Calendar.MONTH, -12);
        String format1 = sdf.format(instance.getTime());
        System.out.println(format1);
    }

    @Test
    public void test05() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> fullDayList = new ArrayList<String>();
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, 2021);
        calendar.set(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        int count = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        for (int i = 0; i <= count - 1; ) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.YEAR, 2021);
            cal.set(Calendar.MONTH, 2);
            cal.set(Calendar.DAY_OF_MONTH, 0);
            String end = sdf.format(cal.getTime());
            if (sdf.format(calendar.getTime()).equals(end))
                break;
            calendar.add(Calendar.DAY_OF_MONTH, i == 0 ? +0 : +1);
            i++;
            fullDayList.add(sdf.format(calendar.getTime()));
            fullDayList.add(sdf.format(calendar.getTime()) + "挑战目标");
        }
        for (String s : fullDayList) {
            System.out.println(s);
        }
    }

    @Test
    public void test06() {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, 2021);
        calendar.set(Calendar.MONTH, 2);
        calendar.set(Calendar.DAY_OF_MONTH, 0);
        System.out.println(YMD.format(calendar.getTime()));
    }

    @Test
    public void test07() {
        String url = "http://opendata.baidu.com/api.php?";
    }

    @Test
    public void test08() {
        String text = "";
        String a = "";
        String b = "2021-04";
        String date_param = "";
        for (int i = 1; i <= 30; i++) {
            text = text + "\"\",";
            if (i < 10) {
                a = a + "\"" + b + "-0" + i + "\",";
                date_param = date_param + "\"target-0" + i + "\",";
            } else {
                a = a + "\"" + b + "-" + i + "\",";
                date_param = date_param + "\"target-" + i + "\",";
            }
        }
        String[] split = a.split(",");
        String[] title = new String[split.length];
        for (int i = 0; i < title.length; i++) {
            title[i] = split[i];
        }
        String[] titles1 = {"家用车非新车签单保费目标分解", "", "", "", "", "", "", "", ""};
        String[] titles2 = {"", "", "", "", "", "", ""};
        String[] aaa = new String[titles1.length+title.length+titles2.length];
        System.arraycopy(titles1,0,aaa,0,titles1.length);
        System.arraycopy(title,0,aaa,titles1.length,title.length);
        System.arraycopy(titles2,0,aaa,titles1.length+title.length,titles2.length);
        for (int i = 0; i < aaa.length; i++) {
            System.out.println(aaa[i]);
        }

        //System.out.println(a);
        //text = text.substring(0, text.length() - 1);
        //System.out.println(text);
    }
    @Test
    public void test10() {

    }

    @Test
    public void test09() throws ParseException {
        String a = "2021年4月";
        String format = YMD.format(YMD.parse(a));
        System.out.println(format);
    }

    @Test
    public void test11() {
        Date date = new Date();
        String format = MD.format(date);
        int s = Integer.parseInt(format.split("-")[2]);
        System.out.println(s);
        String a= "123456789";
        String substring = a.substring(0, a.length() - 1);
        System.out.println(substring);
        System.out.println(format);
    }

    @Test
    public void test12() {
        Calendar calendar = Calendar.getInstance();
        Date date = new Date();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK)-1;
        System.out.println(week);
    }
    @Test
    public void test13() {
        //String[] a = {"1"};
        String a = "1,2";
        String[] split = a.split(",");
        System.out.println(split.length-2);
        for (String s : split) {
            System.out.println(s);
        }
    }
    @Test
    public void test14(){
        for (int i = 0; i < 100; i++) {
            String s = RandomStringUtils.randomNumeric(4);
            System.out.println(s);
        }
    }

    @Test
    public void test15(){
        String a = "41052319990523300X";
        String substring = a.substring(6, 10);
        String format = YMD.format(new Date());
        String year = format.split("-")[0];
        int i = Integer.parseInt(year) - Integer.parseInt(substring);
        System.out.println(i);
        String substring1 = a.substring(16, 17);
        String sex = "0";
        if (Integer.parseInt(substring1)%2==0){
            sex = "1";
        }else {
            sex = "0";
        }
        System.out.println(sex);
        System.out.println(substring1);
    }
}
